{% macro paginate(page_obj) %}
{% if page_obj.pages > 1 %}
<div class="pagination .pagination-mini">
<ul>
	<li {% if not page_obj.has_prev %}class="disabled"{% endif %}><a href="?p={{page_obj.page-1}}">Prev</a></li>
	{% for i in range(1, page_obj.pages+1) %}
		<li {% if i == page_obj.page %}class="active"{% endif %}>
			<a href="?p={{i}}">{{i}}</a>
		</li>
	{% endfor %}
	<li {% if not page_obj.has_next %}class="disabled"{% endif %}><a href="?p={{page_obj.page+1}}">Next</a></li>
</ul>
</div>
{% endif %}
{% endmacro %}

{% macro status_label(status,status_message) %}
{%if status == 1 %}
<span class="label label-success">{{status_message}}</span>
{%elif status == 0%}
<span class="label">{{status_message}}</span>
{%elif status == 2%}
<span class="label label-warning">{{status_message}}</span>
{%elif status == 3%}
<span class="label label-important">{{status_message}}</span>
{%endif%}
{% endmacro %}

{% macro render_item(request, endpoint, display, cls='', icon_cls='', active='') %}
<li {% if request.endpoint == endpoint or active == endpoint %} class='active' {% endif %}>
    <a class='{{cls}}' href="{{url_for(endpoint)}}"><i class="{{icon_cls}}"></i> {{display}}</a>
</li>
{% endmacro %}

{% macro render_errors(field) %}
{% if field.errors %}
<span class="help-inline">
    {% for error in field.errors %}
    {{ error }}
    {% endfor %}
</span>
{% endif %}
{% endmacro %}

{% macro render_tips(field) %}
{% if field.description %}
<span class="tips">{{ field.description }}</span>
{% endif %}
{% endmacro %}

{% macro message() %}
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="msg">
{% for category,message in messages %}
<div class="alert alert-{{category}}">
	<button class="close" data-dismiss="alert" type="button">×</button>
	{{message}}
</div>
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% endmacro %}

{% macro ueditor(id) %}
<script type="text/javascript">
  var ue = UM.getEditor('{{id}}',{
      //这里可以选择自己需要的工具按钮名称,此处仅选择如下七个
      toolbar:['fullscreen source | bold italic underline | insertorderedlist insertunorderedlist | link unlink | image insertvideo'],
      imageUrl:"/",
      imagePath:"",
      imageFieldName:"upfile",
      imageScaleEnabled:false,
      autoFloatEnabled:true,
      topOffset:41,
      //关闭字数统计
      wordCount:false,
      //关闭elementPath
      elementPathEnabled:false,
      //默认的编辑区域高度
      // initialFrameHeight:500
      //更多其他参数，请参考umeditor.config.js中的配置项
      focus: true
  });
</script>
{% endmacro %}
